##
# This script set linux specific flags (GNU GCC)
#
##
Import('env')

print "Reading linux configuration script"

# Set release/debug flags
if env.get('RELEASE'):
	env.AppendUnique(CCFLAGS = ['-Os'])
	env.AppendUnique(CPPDEFINES = ['NDEBUG'])
else:
	env.AppendUnique(CCFLAGS = ['-g'])

if env.get('LOGGING'):
	env.AppendUnique(CPPDEFINES = ['-DTB_LOG'])

env.AppendUnique(CPPDEFINES = ['WITH_POSIX', '__linux__'])
env.AppendUnique(CFLAGS = ['-std=gnu99'])
env.AppendUnique(CCFLAGS = ['-Wall', '-Wextra', '-fPIC'])
env.AppendUnique(LIBS = ['uuid'])
env.AppendUnique(LINKFLAGS = ['-ldl', '-lpthread'])

# Set arch flags
target_arch = env.get('TARGET_ARCH')
if target_arch in ['x86']:
	env.AppendUnique(CCFLAGS = ['-m32'])
	env.AppendUnique(LINKFLAGS = ['-m32'])
elif target_arch in ['x86_64']:
	env.AppendUnique(CCFLAGS = ['-m64'])
	env.AppendUnique(LINKFLAGS = ['-m64'])
elif target_arch.find('v7a-hard') > 0:
	env.AppendUnique(CPPFLAGS = ['-march=armv7-a'])
	env.AppendUnique(CPPFLAGS = ['-mfloat-abi=hard'])
	env.AppendUnique(CCFLAGS = ['-mfloat-abi=hard'])
	env.AppendUnique(LINKFLAGS = ['-mfloat-abi=hard'])
elif target_arch.find('v7a') > 0:
	env.AppendUnique(CPPFLAGS = ['-march=armv7-a'])
elif target_arch.find('arm64') >= 0:
	env.AppendUnique(CPPFLAGS = ['-march=armv8-a'])
else:
	env.AppendUnique(CPPFLAGS = ['-march=armv5te'])
